// pages/staff/my/helpcenter.js
const app = getApp()
var CONFIG = require("../../../config/config.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        swiperNav: {
        　　i: 0,
        　　arr: [
            　　　{ id: '', name: "全部" },
        　　]
        },
        centerarr:[],
        id:'',
        type:1,
    },

    swiperNav: function (e) {
        // console.log(e);
        var that = this;
        　/*获取可视窗口宽度*/
        var w = wx.getSystemInfoSync().windowWidth;
        var leng = that.data.swiperNav.arr.length;
        var i = e.target.dataset.i;
        var disX = (i - 2) * w / leng;
        if (i != that.data.swiperNav.i) {
            that.setData({
                'swiperNav.i': i
            })
        }
        var id = e.target.dataset.id;
        that.setData({
        　　'swiperNav.x': disX,
            id: id,
            centerarr:[],
        })
        that.helpCenter(id);
    },
    

    // 分类
    quesionClass(){
        let that = this;
        var type = that.data.type;
        if (Number(type) == 2) {
            var url = CONFIG.API_HOST + 'crm/My/quesionClassCw'
        } else {
            var url = CONFIG.API_HOST + 'crm/My/quesionClass'
        }
        wx.request({
            url: url,
            method: 'GET',
            success: function (res) {
                if (res.data.status == 1001 || res.data.status == '1001'){

                    var swiperNav = that.data.swiperNav.arr;
                    var data = res.data.data;
                    var data1 = swiperNav.concat(data);
                    // console.log(data1)
                    that.setData({
                        'swiperNav.arr': data1
                    })
                }
            },
            
        })
    },

    // 分类下的列表
    helpCenter(cid) {
        wx.showLoading({
            title: '加载中~',
        })
        let that = this;
        var type = that.data.type;
        if (Number(type) == 2) {
            var url = CONFIG.API_HOST + 'crm/My/helpCenterCw'
        } else {
            var url = CONFIG.API_HOST + 'crm/My/helpCenter'
        }
        wx.request({
            url: url,
            method: 'GET',
            data:{
                cid:cid,
            },
            success: function (res) {
                wx.hideLoading();
                if (res.data.status == 1001 || res.data.status == '1001') {
                    // console.log(res.data);
                    var data = res.data.data;
                    that.setData({
                        centerarr:data
                    })
                }
            },

        })
    },
    

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        var type = options.type;
        that.setData({
            type: options.type
        })
        if(Number(type)==2){
            wx.setNavigationBarTitle({
                title: '财务规章制度'
            })
        }else{
            wx.setNavigationBarTitle({
                title: '使用指南'
            })
        }
        that.quesionClass();
        that.helpCenter('');
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})